﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using BCCommon;
using BCDto.OA.Notification.NotificationCategory;
using BCService.OA.Notification.NotificationCategory;
using BCService.Utils;
using BlackCoffeeRESTful.Configs;

namespace BlackCoffeeRESTful.Controllers.Management.OA.Notification.NotificationCategory
{
    /// <summary>
    /// 通知分类
    /// </summary>
    [ApiExplorerSettings(GroupName = "OAAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class NotificationCategoryController : ManagementBaseController
    {
        private readonly INotificationCategoryService notificationCategoryService;

        public NotificationCategoryController(INotificationCategoryService notificationCategoryService)
        {
            this.notificationCategoryService = notificationCategoryService;
        }

        #region 添加通知分类
        /// <summary>
        ///  添加通知分类
        /// </summary>
        /// <param name="requestDto">通知分类信息</param>
        /// <response code="201">添加通知分类成功</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加通知分类")]
        [ProducesResponseType(typeof(NotificationCategoryDto), 201)]
        public IActionResult Post(
            [FromBody]NotificationCategoryRequestDto requestDto)
        {
            var result = this.notificationCategoryService.Add(requestDto);
            return this.Created(string.Format("api/v1/sim/NotificationCategory/{0}", result.NotificationCategoryId), result);
        }
        #endregion

        #region 修改通知分类
        /// <summary>
        ///  修改通知分类
        /// </summary>
        /// <param name="notificationCategoryId">通知分类Id</param>
        /// <param name="requestDto">通知分类信息</param>
        /// <response code="200">修改通知分类成功</response>
        /// <returns></returns>
        [HttpPut("{notification_category_id}")]
        [Log("修改通知分类")]
        [ProducesResponseType(typeof(NotificationCategoryDto), 200)]
        public IActionResult Put([FromRoute(Name = "notification_category_id")]long notificationCategoryId, [FromBody]NotificationCategoryRequestDto requestDto)
        {
            NotificationCategoryPutDto putDto = requestDto.As<NotificationCategoryPutDto>();
            putDto.NotificationCategoryId = notificationCategoryId;
            return this.Ok(this.notificationCategoryService.Update(putDto));
        }
        #endregion

        #region 删除通知分类
        /// <summary>
        ///  删除通知分类
        /// </summary>
        /// <param name="notificationCategoryId">通知分类Id</param>
        /// <response code="204">删除通知分类成功</response>
        /// <returns></returns>
        [HttpDelete("{notification_category_id}")]
        [Log("删除通知分类")]
        public IActionResult Delete([FromRoute(Name = "notification_category_id")]long notificationCategoryId)
        {
            this.notificationCategoryService.Delete(notificationCategoryId);
            return this.NoContent();
        }
        #endregion

        #region 获取通知分类
        /// <summary>
        ///  获取通知分类
        /// </summary>
        /// <param name="notificationCategoryId">通知分类Id</param>
        /// <response code="200">获取通知分类</response>
        /// <returns></returns>
        [HttpGet("{notification_category_id}")]
        [ProducesResponseType(typeof(NotificationCategoryDto), 200)]
        public IActionResult Get([FromRoute(Name = "notification_category_id")]long notificationCategoryId)
        {
            return this.Ok(this.notificationCategoryService.GetEntity(notificationCategoryId));
        }
        #endregion

        #region 获取通知分类列表
        /// <summary>
        ///  获取通知分类列表
        /// </summary>
        /// <response code="200">获取通知分类列表</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(NotificationCategoryDto), 200)]
        public IActionResult Get()
        {
            return this.Ok(this.notificationCategoryService.GetList());
        }
        #endregion

        #region 获取通知分类（分页）
        /// <summary>
        ///  获取通知分类（分页）
        /// </summary>
        /// <param name="notificationCategoryName">通知分类名称</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="pageIndex">以 1 起始的页码 (默认 1)。</param>
        /// <param name="pageSize">每页要显示的行数 (默认 10)。</param>
        /// <response code="200">获取通知分类（分页）</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<NotificationCategoryDto>), 200)]
        public IActionResult Query([FromQuery(Name = "notification_category_name")]string notificationCategoryName,
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            int pageIndex = 1,
            int pageSize = 10)
        {
            return this.Ok(this.notificationCategoryService.Query(notificationCategoryName,start,end,pageIndex, pageSize));
        }
        #endregion

    }
}
